package com.lei.baselibrary.base.ext

import android.view.View
import android.widget.Button
import android.widget.EditText
import com.lei.baselibrary.base.data.protocol.BaseResp
import com.lei.baselibrary.base.rx.BaseFunc
import com.lei.baselibrary.base.rx.BaseFuncBoolean
import com.lei.baselibrary.base.rx.BaseSubScribe
import com.trello.rxlifecycle.LifecycleProvider
import rx.Observable
import rx.android.schedulers.AndroidSchedulers
import rx.schedulers.Schedulers
import kotlin.random.Random

/**
 * @ProjectName : MyMall
 * @Author : 雷金泷
 * @Time : 2021/2/25 13:04
 * @Description : 文件描述
 */
//kotlin 通用扩展
//扩展 Observable执行
fun <T> Observable<T>.excute(subscriber:BaseSubScribe<T>,lifecycleProvider: LifecycleProvider<*>){
    this.subscribeOn(Schedulers.io())
        .observeOn(AndroidSchedulers.mainThread())
        .compose(lifecycleProvider.bindToLifecycle())
        .subscribe(subscriber)
}
//扩展数据转换
fun<T> Observable<BaseResp<T>>.convert():Observable<T>{
    return this.flatMap(BaseFunc())
}

//
fun<T> Observable<BaseResp<T>>.convertBoolean():Observable<Boolean>{
    return this.flatMap(BaseFuncBoolean())
}

//扩展的点击事件

fun View.onClick(listener:View.OnClickListener):View{
    setOnClickListener(listener)
    return this
}